home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / news / thor / rexx / bulkmail.thor < prev    next >
Text File  |  1998-05-24  |  8KB  |  210 lines

  1. /*
  2. $VER: BulkMail.thor 2.0 (12.3.97)
  3. (c)  Neil Bothwick <neil@wirenet.co.uk> 1997
  4. */
  5. /* Searches the User database for Comments or Aliases   */
  6. /* containing the supplied string, and then sends each  */
  7. /* match a copy of the currently selected EMail event.  */
  8. /* V2.0 adds the option to send a single mail to all    */
  9. /* recipients, using either Cc: or Bcc: and a hotlist   */
  10. /* of commonly used search strings                      */
  11.  
  12. options results
  13.  
  14. /* ;;; Set variables */
  15. EVE_ENTERMSG      =  0            /* Event is enter   */
  16. EDF_DELETED       = '00000001'x   /* Event is deleted */
  17. EDF_DONE          = '00000004'x   /* Event is done    */
  18. EDF_FREEZE        = '00000020'x   /* Event is frozen  */
  19. CDF_MAIL          = '00000002'x   /* Mail conference  */
  20. ;;;
  21. /* ;;; Get Thor arexx port and load bbsread.library */
  22. thorport = address()
  23. if left(thorport,5) ~= 'THOR.' then do
  24.     say 'FixMail.thor must be run from within Thor.'
  25.     end
  26.  
  27. if ~show('p', 'BBSREAD') then do
  28.     address command
  29.     'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  30.     'WaitForPort BBSREAD'
  31.     end
  32. ;;;
  33. /* ;;; Get current system info and selected event number */
  34. address(thorport)
  35. 'CURRENTSYSTEM stem CURRENT'
  36. System = CURRENT.BBSNAME
  37. drop CURRENT.
  38. 'GETSELECTEDEVENT'
  39. if rc = 5 then call ExitMsg('Event window not open')
  40. if rc > 5 then call ExitMsg(THOR.LASTERROR)
  41. EventNo = result
  42. address(bbsread)
  43. drop SYSINFO.
  44. 'GETBBSDATA "'System'" SYSINFO'
  45. DataPath = SYSINFO.BBSPATH
  46. ;;;
  47. /* ;;; Get event details */
  48. address(bbsread)
  49. 'READBREVENT "'System'" eventnr' EventNo 'datastem EVENTDATA tagsstem EVENTTAGS'
  50. if(rc > 0) then call ExitMsg(BBSREAD.LASTERROR)
  51. ;;;
  52. /* ;;; Make sure it is an EMail event and an Enter event */
  53. drop CONFINFO.
  54. 'GETCONFDATA "'System'" "'EVENTTAGS.CONFERENCE'" stem CONFINFO'
  55. if bitand(CONFINFO.FLAGS,CDF_MAIL) ~= CDF_MAIL then call ExitMsg('Selected event is not an EMail event')
  56. if EVENTDATA.EVENTTYPE ~= EVE_ENTERMSG then call ExitMsg('Selected event is not an Enter event')
  57. ;;;
  58. /* ;;; Get string to match on */
  59. address(thorport)
  60. DefaultStr = ''
  61. do while 1 = 1
  62.     'REQUESTSTRING TITLE "Search string" BT "_OK|_Address|_Hotlist|_Cancel" BODY "Enter string to search for\nin User Database" ID "'DefaultStr'"'
  63.     if rc > 5 then call ExitMsg(THOR.LASTERROR)
  64.     MatchString = result
  65.     select
  66.         when THORRC = 1 then leave
  67.         when THORRC = 2 then DefaultStr = EVENTTAGS.TOADDR
  68.         when THORRC = 3 then do
  69.             if ~open(hl,DataPath'BulkMail.hotlist','R') then call ExitMsg('Failed to open hotlist')
  70.             drop LIST.
  71.             n = 0
  72.             do while ~eof(hl)
  73.                 line = readln(hl)
  74.                 if line = '' then leave
  75.                 n = n + 1
  76.                 interpret 'LIST.'n' = line'
  77.                 end
  78.             LIST.COUNT = n
  79.             call close(hl)
  80.             'REQUESTLIST instem LIST outstem tmp title "Select search item"'
  81.             if rc = 5 then exit
  82.             if rc > 0 then call ExitMsg(THOR.LASTERROR)
  83.             DefaultStr = result
  84.             end
  85.         otherwise exit
  86.         end
  87.     end
  88. ;;;
  89. /* ;;; Search User Database for matches */
  90. address(thorport)
  91. 'REQUESTNOTIFY "Search Alias or Comment fields?" "_Alias|_Comment|_Cancel"'
  92. Choice = result
  93. select
  94.     when Choice = 1 then Searchfield = 'ALIAS'
  95.     when Choice = 2 then Searchfield = 'COMMENT'
  96.     otherwise exit
  97.     end
  98.  
  99. address(bbsread)
  100. 'SEARCHBRUSER "'System'" STEM SEARCHRESULT SEARCH "#?'MatchString'#?"' SearchField
  101. if(rc ~= 0) then call ExitMsg(BBSREAD.LASTERROR)
  102. if SearchResult.COUNT = 0 then call ExitMsg('No matches for *"'MatchString'*" found in User database')
  103.  
  104. /* Read names and addresses from user database */
  105. drop Names. Addresses. List.
  106. do i = 1 to SearchResult.COUNT
  107.     UserNo = SearchResult.i.USERNR
  108.     'READBRUSER BBSNAME "'System'" USERNR' UserNo 'TAGSSTEM USERTAGS'
  109.     if rc > 0 then call ExitMsg(BBSREAD.LASTERROR)
  110.     interpret 'Names.'i' = USERTAGS.NAME'
  111.     interpret 'Addresses.'i' = USERTAGS.ADDRESS'
  112.     interpret 'List.'i' = left(USERTAGS.NAME,30)||USERTAGS.ADDRESS'
  113.     end
  114. Names.COUNT     = SearchResult.COUNT
  115. Addresses.COUNT = SearchResult.COUNT
  116. List.COUNT      = SearchResult.COUNT
  117. ;;;
  118. /* ;;; Use all or select? */
  119. address(thorport)
  120. 'REQUESTNOTIFY "'SearchResult.COUNT 'matches found" "_All|_Select|_Cancel"'
  121. if result = 0 then exit
  122. if result = 2 then do           /* Select addresses from list */
  123.     drop Selected.
  124.     'REQUESTLIST instem LIST outstem SELECTED title "Select addresses to send to" MULTISELECT'
  125.     if rc = 5 then exit
  126.     if rc > 0 then call ExitMsg(THOR.LASTERROR)
  127.  
  128.     /* Copy selected entries to Names. and Addresses. stems */
  129.     drop Names. Addresses.
  130.     do i = 1 to Selected.COUNT
  131.         interpret 'Names.'i' = strip(left(Selected.'i',30))'
  132.         interpret 'Addresses.'i' = strip(substr(Selected.'i',31))'
  133.         end
  134.     Names.COUNT = Selected.COUNT
  135.     Addresses.COUNT = Selected.COUNT
  136.     end
  137. ;;;
  138. /* ;;; Create separate or copied messages */
  139. address(thorport)
  140. 'REQUESTNOTIFY "Send a separate email to each recipient?\nOr one mail with all addresses\nincluded in Cc: or Bcc: headers?" "_Separate|_Cc:|_Bcc:|Cancel"'
  141. if rc > 0 then ExitMsg(THOR.LASTERROR)
  142. select
  143.     when result = 0 then exit
  144.     when result = 1 then do                     /* Create separate events for each recipient */
  145.         address(bbsread)
  146.         do i = 1 to Names.COUNT
  147.             interpret 'EVENTTAGS.TONAME = Names.'i
  148.             interpret 'EVENTTAGS.TOADDR = Addresses.'i
  149.             'WRITEBREVENT BBSNAME "'System'" EVENT' EVE_ENTERMSG 'STEM EVENTTAGS'
  150.             if rc > 0 then call ExitMsg(BBSREAD.LASTERROR)
  151.             end
  152.  
  153.         /* Delete original event? */
  154.         address(thorport)
  155.         'REQUESTNOTIFY "'i-1 'Email events created\nDelete original event?" "_Yes|_No"'
  156.         if (result = 1) then do
  157.             address(bbsread)
  158.             'UPDATEBREVENT bbsname "'System'" eventnr' EventNo 'SETDELETED'
  159.             end
  160.         end
  161.     when result = 2 | result = 3 then do        /* Add Cc: or Bcc: headers to original event */
  162.         if result = 2 then hdr = 'Cc: '
  163.         else hdr = 'Bcc: '
  164.         /* Build header string, adding line feed when max length is reached */
  165.         Header = ''
  166.         AddressStr = hdr||Addresses.1
  167.         do i = 2 to Addresses.COUNT
  168.             interpret 'NextAddress = Addresses.'i
  169.             if length(AddressStr','NextAddress) > 250 then do
  170.                 Header = Header||AddressStr||'0a'x
  171.                 AddressStr = hdr
  172.                 end
  173.             else AddressStr = AddressStr','
  174.             AddressStr = AddressStr||NextAddress
  175.             end
  176.         if AddressStr > '' then Header = Header||AddressStr||'0a'x
  177.  
  178.         /* Write headers to message */
  179.         TmpFile = 'T:BulkMail.'time(s)
  180.         if ~open(out,TmpFile,'W') then ExitMsg('Failed to open temporary file' TmpFile)
  181.         if ~open(in,DataPath||EVENTTAGS.MSGFILE) then ExitMsg('Failed to open message file')
  182.         call writech(out,Header)            /* Write cc headers */
  183.         nextline = readln(in)               /* See if message file starts with a custom header */
  184.         firstword = word(nextline,1)        /* otherwise write a blank line */
  185.         if pos(':',firstword) ~= length(firstword) then call writeln(out,'')
  186.         call writeln(out,nextline)
  187.         do until eof(in)
  188.             call writech(out,readch(in,20000))
  189.             end
  190.  
  191.         call close(out)
  192.         call close(in)
  193.         address command
  194.         'delete >NIL:' DataPath||EVENTTAGS.MSGFILE
  195.         'copy >NIL:' TmpFile DataPath||EVENTTAGS.MSGFILE
  196.         'delete >NIL:' TmpFile
  197.         end
  198.     otherwise exit
  199.     end
  200. ;;;
  201. exit
  202.  
  203. /* ;;; Exit with a message */
  204. ExitMsg:
  205.     parse arg ErrTxt
  206.     address(thorport)
  207.     'REQUESTNOTIFY "'ErrTxt'" "Abort"'
  208.     exit
  209. ;;;
  210.